package com.zhangfb95.crosschain.console.command;

import com.zhangfb95.crosschain.console.enums.CommandEnum;
import com.zhangfb95.crosschain.sdk.CrossChainClient;
import com.zhangfb95.crosschain.sdk.infra.model.service.dto.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zhangfubing
 * @since 2023/12/21
 */
@Component
public class UserInfoCommand implements Command {

    @Autowired
    private CrossChainClient crossChainClient;

    @Override
    public CommandEnum command() {
        return CommandEnum.USERINFO;
    }

    @Override
    public boolean handle(String[] args) {
        if (isHelp(args)) {
            printHelpInfo();
            return false;
        }

        UserInfo userInfo = crossChainClient.getLoginedUserInfo();
        if (userInfo == null) {
            System.out.println("Result: user not login");
            return false;
        }

        System.out.println("Result: success");
        System.out.println("userinfo: " + userInfo.getUserId());
        System.out.println("username: " + userInfo.getUsername());
        System.out.println("secret: " + userInfo.getUserSecret());

        return false;
    }

    private void printHelpInfo() {
        System.out.println("Usage: userinfo");
    }
}
